<?php
require_once 'global.inc.php';

//check to see if they're logged in
if(!isset($_SESSION['admin_logged_in'])) {
	header("Location: index.php");
}

//get the user object from the session
$user = unserialize($_SESSION['admin_user']);

$products = $GLOBALS['DB']->select("items");

?>
<!DOCTYPE html>
<html>
	<?php include 'header.php';?>
	<body>
		<!-- Navigation start -->
		<div class="navbar navbar-inverse navbar-fixed-top">
			<div class="navbar-inner">
				<div class="container">
					<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
						<span class="icon-bar"></span>
					</button>
				</div>
			</div>
		</div>
		<!-- Navigation end -->

		<!-- Content start -->
		<div class="container">
			<div class="row">
				<div class="span12">
					Welcome <?php echo $user->username; ?>. You've been registered and logged in. <a href="logout.php">Log Out</a> | <a href="index.php">Return to Main page</a>
					<h1>Product list</h1>
					<a href="new.php">Add new product</a>
				</div>
			</div>
			
			<div class="row">
				<div class="span12">
					<table class="table">
						<tr>
							<th>Id</th>
							<th>Name</th>
							<th>Price</th>
							<th>Picture</th>
							<th>Description</th>
							<th>Type</th>
							<th>Unit in stock</th>
							<th>Unit sold</th>
							<th></th>
							<th></th>
						</tr>
						<?php foreach ($products as $product) : ?>
						<tr>
							<td><?php echo $product['item_id']?></td>
							<td><?php echo $product['item_name']?></td>
							<td><?php echo $product['price']?></td>
							<td><img src="<?php echo BASE_URL.'upload/'.$product['picture']?>" alt="<?php echo $product['item_name'] ?>"></td>
							<td><?php echo $product['description']?></td>
							<td><?php echo $product['type']?></td>
							<td><?php echo $product['unit_instock']?></td>
							<td><?php echo $product['unit_sold']?></td>
							<td><a href="edit.php?product=<?php echo $product['item_id']?>">Edit</a></td>
							<td><a href="delete.php?product=<?php echo $product['item_id']?>">Delete</a></td>
						</tr>
						<?php endforeach; ?>
					</table>
					
				</div>
			</div>
			
		</div>


		<!-- Content end -->
		<?php include 'footer.php';?>
		<!-- Javascript -->
		<script src="js/jquery.js"></script>
		<script src="js/bootstrap.min.js"></script>
	</body>
</html>